#!/usr/bin/python

import WykopRespEntryComment
import WykopRespComment
import WykopRespLink
import WykopRespEmbed

class WykopRespMywykop:
    
    def _setData(self, Data):
	
        self.type = Data['type']
        if self.type == 'link':
            self.title = Data['title']
            self.description = Data['description']
            self.tags = Data['tags']
            self.source_url = Data['source_url']
            self.comment_count = Data['comment_count']
            self.report_count = Data['report_count']
            self.group = Data['id']
            self.preview = Data['preview']
            self.user_lists =Data['user_lists']
            self.plus18 = Data['plus18']
            self.status = Data['status']
            self.can_vote =Data['can_vote']
            self.has_own_content =Data['has_own_content']
            self.category =Data['category']
            self.comments = Data['comments']
            self.commented = Data['commented']		
        elif self.type == 'entry':
            self.id = Data['id']
            self.body	= Data['body']
            self.receiver	= Data['receiver']
            self.receiver_avatar	= Data['receiver_avatar']
            self.receiver_avatar_med = Data['receiver_avatar_med']	
            self.receiver_avatar_lo	= Data['receiver_avatar_lo']
            self.receiver_group	= Data['receiver_group']
            self.voters = Data['voters']
            try:
                self.embed	= Data['embed']
            except KeyError:
                self.embed =  WykopRespEmbed.WykopRespEmbed()
        self.url = Data['url']
        self.date = Data['date']
        self.vote_count = Data['vote_count']
        self.author = Data['author']
        self.author_avatar = Data['author_avatar']	
        self.author_avatar_med	= Data['author_avatar_med']
        self.author_avatar_lo	= Data['author_avatar_lo']
        self.author_group	= Data['author_group']
		
    def _normalizeData(self,Data):
        List = []
        for El in Data:
            Obj = WykopRespMywykop()
            Obj._setData(El)
            if Obj.type == 'link':
                A = WykopRespComment.WykopRespComment()
                Obj.comments = A._normalizeDatatoList(Obj.comments)
            List.append(Obj)
        return List